package com.ppt.android.activity

import android.view.View
import android.webkit.WebSettings
import androidx.activity.viewModels
import androidx.lifecycle.rxLifeScope
import com.ppt.android.activity.vm.MainViewModel
import com.ppt.android.base.BaseActivity
import com.ppt.android.base.utils.BarUtils

import com.ppt.android.databinding.ActivityWebviewBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class WebViewActivity :
    BaseActivity<ActivityWebviewBinding, MainViewModel>() {


    override fun ActivityWebviewBinding.initView() {
        BarUtils.setStatusBarLightMode(this@WebViewActivity, true)
        initStatusBarHeight(mBinding.statusView)
        mBinding.goBack.setOnClickListener {
            finish()
        }
        initWebView()
    }


    override val mViewModel by viewModels<MainViewModel>()

    override fun initObserve() {
    }

    override fun initRequestData() {


    }

    private fun initWebView(){
        val settings: WebSettings = mBinding.webView.settings
        mBinding.webView.clearCache(true)
        settings.cacheMode = WebSettings.LOAD_NO_CACHE
        settings.loadWithOverviewMode = true
        settings.useWideViewPort = true
        settings.databaseEnabled = true
        settings.domStorageEnabled = true
        settings.javaScriptCanOpenWindowsAutomatically = true
        settings.setSupportMultipleWindows(true)

        mBinding.webView.loadUrl("https://www.wallpapermasterx.com/privacy.html")
    }


    private fun initStatusBarHeight(view: View) {
        rxLifeScope.launch {
            val mLayoutParams = view.layoutParams
            val statusBarHeight = BarUtils.getStatusBarHeight()
            mLayoutParams.height = statusBarHeight
            view.layoutParams = mLayoutParams
        }
    }

}